rem Requires XSU12_ver1_2_1.zip installed or XDK 9.0.x
rem On Oracle 8.1.7 requires, for example:
rem call sys.dbms_java.loadjava('-v -r -grant PUBLIC -synonym lib/xmlparserv2.jar')
rem call sys.dbms_java.loadjava('-v -r -grant PUBLIC -synonym lib/xsu12.jar')
rem xmlparserv2.jar is regulary installed on creation step
rem xsu12.jar requires manually install
rem Requires create and drop public synonym privileges

CREATE OR REPLACE PACKAGE Jowa authid current_user AS
  FUNCTION initialize return NUMBER;
  PROCEDURE setCgiVar(varName VARCHAR2, varValue VARCHAR2);
  PROCEDURE setCgiVars(varNames LONG RAW, varValues LONG RAW);
  FUNCTION getCgiVar(varName VARCHAR2) return VARCHAR2;
END Jowa;
/
show errors

CREATE OR REPLACE PACKAGE BODY Jowa AS
  FUNCTION initialize return NUMBER
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.Jowa.INITIALIZE() return int';
  PROCEDURE setCgiVar(varName VARCHAR2, varValue VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.Jowa.SETCGIVAR(java.lang.String, java.lang.String)';
  PROCEDURE setCgiVars(varNames LONG RAW, varValues LONG RAW)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.Jowa.SETCGIVARS(byte [], byte[])';
  FUNCTION getCgiVar(varName VARCHAR2) return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.Jowa.GETCGIVAR(java.lang.String) return java.lang.String';
END Jowa;
/
show errors

CREATE OR REPLACE PACKAGE JowaInit authid current_user AS
  FUNCTION authorize return NUMBER;
END JowaInit;
/
show errors

CREATE OR REPLACE PACKAGE BODY JowaInit AS
  FUNCTION authorize return NUMBER
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaInit.AUTHORIZE() return int';
END JowaInit;
/
show errors

CREATE OR REPLACE PACKAGE JowaSec authid current_user AS
  PROCEDURE setAuthorization(scheme NUMBER);
  FUNCTION getAuthorization return NUMBER;
  FUNCTION getUserId return VARCHAR2;
  PROCEDURE setUserId(cuser VARCHAR2);
  FUNCTION getPassword return VARCHAR2;
  PROCEDURE setPassword(pass VARCHAR2);
  FUNCTION getClientIp return VARCHAR2;
  PROCEDURE setClientIp(ip VARCHAR2);
  FUNCTION getProtectionRealm return VARCHAR2;
  PROCEDURE setProtectionRealm(realm VARCHAR2);
END JowaSec;
/
show errors

CREATE OR REPLACE PACKAGE BODY JowaSec AS
  PROCEDURE setAuthorization(scheme NUMBER)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.SETAUTHORIZATION(int)';
  FUNCTION getAuthorization return NUMBER
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.GETAUTHORIZATION() return int';
  FUNCTION getUserId return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.GETUSERID() return java.lang.String';
  PROCEDURE setUserId(cuser VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.SETUSERID(java.lang.String)';
  FUNCTION getPassword return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.GETPASSWORD() return java.lang.String';
  PROCEDURE setPassword(pass VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.SETPASSWORD(java.lang.String)';
  FUNCTION getClientIp return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.GETCLIENTIP() return java.lang.String';
  PROCEDURE setClientIp(ip VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.SETCLIENTIP(java.lang.String)';
  PROCEDURE setProtectionRealm(realm VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.SETPROTECTIONREALM(java.lang.String)';
  FUNCTION getProtectionRealm return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JowaSec.GETPROTECTIONREALM() return java.lang.String';
END JowaSec;
/
show errors

CREATE OR REPLACE PACKAGE JwpgDocLoad authid current_user AS
  PROCEDURE downloadFile(filename VARCHAR2, caching BOOLEAN);
  PROCEDURE downloadFile(filename VARCHAR2);
  PROCEDURE downloadFile(locator BLOB);
  PROCEDURE downloadFile(locator CLOB);
  FUNCTION isFileDownload return NUMBER;
  FUNCTION getDownloadFile return VARCHAR2;
  FUNCTION getDownloadBlob return BLOB;
  FUNCTION getDownloadClob return CLOB;
  FUNCTION getDownloadXML return XMLType deterministic;
  FUNCTION getContentLength return pls_integer;
END JwpgDocLoad;
/
show errors

CREATE OR REPLACE PACKAGE BODY JwpgDocLoad AS
  PROCEDURE downloadFile(filename VARCHAR2, caching BOOLEAN)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.DOWNLOADFILE(java.lang.String, boolean)';
  PROCEDURE downloadFile(filename VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.DOWNLOADFILE(java.lang.String)';
  PROCEDURE downloadFile(locator BLOB)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.DOWNLOADFILE(BLOB)';
  PROCEDURE downloadFile(locator CLOB)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.DOWNLOADFILE(CLOB)';
  FUNCTION isFileDownload return NUMBER
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.ISFILEDOWNLOAD() return int';
  FUNCTION getDownloadFile return VARCHAR2
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.GETDOWNLOADFILE() return java.lang.String';
  FUNCTION getDownloadBlob return BLOB
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.GETDOWNLOADBLOB() return BLOB';
  FUNCTION getDownloadClob return CLOB
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.GETDOWNLOADCLOB() return CLOB';
  FUNCTION getDownloadXML return XMLType deterministic
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.GETDOWNLOADXML() return oracle.xdb.XMLType';
  FUNCTION getContentLength return pls_integer
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JwpgDocLoad.GETCONTENTLENGTH() return long';
END JwpgDocLoad;
/
show errors

CREATE OR REPLACE PACKAGE JxtpBuff authid current_user AS
  PROCEDURE FLUSH;
  PROCEDURE GETPAGE(p_buff IN BLOB);
  FUNCTION GETPAGE RETURN BLOB;
  PROCEDURE FREE(p_buff IN OUT NOCOPY BLOB);
END JxtpBuff;
/
show errors

CREATE OR REPLACE PACKAGE BODY JxtpBuff AS
  PROCEDURE FLUSH is
  begin
    null; -- Nothing to do in this version
  end FLUSH;

  PROCEDURE GETPAGE(p_buff IN BLOB)
        AS LANGUAGE JAVA
        NAME 'com.prism.toolkit.JxtpBuff.GETPAGE(oracle.sql.BLOB)';
  FUNCTION GETPAGE RETURN BLOB is
   buff BLOB;
  begin
   dbms_lob.createtemporary(buff, true, DBMS_LOB.SESSION);
   GETPAGE(buff);
   return buff;
  end;
  PROCEDURE FREE(p_buff IN OUT NOCOPY BLOB) is
  begin
   dbms_lob.freetemporary(p_buff);
  end;
END JxtpBuff;
/
show errors

prompt Resolving Java classes
alter java class "com.prism.toolkit.JowaArray" resolve;
alter java class "com.prism.toolkit.JowaImage" resolve;
alter java class "com.prism.toolkit.Jowa" resolve;
alter java class "com.prism.toolkit.JowaInit" resolve;
alter java class "com.prism.toolkit.JowaSec" resolve;
alter java class "com.prism.toolkit.Jxtp" resolve;
alter java class "com.prism.toolkit.Jxtf" resolve;
alter java class "com.prism.toolkit.JowaUtil" resolve;
alter java class "com.prism.toolkit.JwpgDocLoad" resolve;
alter java class "com.prism.toolkit.JxtpBuff" resolve;
alter java class "com.prism.toolkit.http.JxtpHttpServletRequest" resolve;
alter java class "com.prism.toolkit.http.JxtpHttpServletResponse" resolve;
alter java class "com.prism.toolkit.http.JxtpHttpServletSession" resolve;
alter java class "com.prism.toolkit.http.test.JxtpHttpServletRequestTest" resolve;
alter java class "com.prism.toolkit.http.test.JxtpHttpServletResponseTest" resolve;
alter java class "com.prism.toolkit.http.test.AllTests" resolve;
alter java class "com.prism.toolkit.http.test.dto.ObjectFactory" resolve;
alter java class "com.prism.toolkit.http.test.dto.Page" resolve;
alter java class "com.prism.toolkit.http.test.dto.PageImpl" resolve;
alter java class "com.prism.toolkit.http.test.dto.PageType" resolve;
alter java class "com.prism.toolkit.http.test.dto.PageTypeImpl" resolve;

prompt Granting privileges
grant execute on Jowa to public;
grant execute on JowaInit to public;
grant execute on JowaSec to public;
grant execute on JwpgDocLoad to public;
grant execute on JxtpBuff to public;

prompt Dropping public synonyms
drop public synonym Jowa;
drop public synonym JowaInit;
drop public synonym JowaSec;
drop public synonym JwpgDocLoad;
drop public synonym JxtpBuff;

prompt Creating public synonyms
create public synonym Jowa for Jowa;
create public synonym JowaInit for JowaInit;
create public synonym JowaSec for JowaSec;
create public synonym JwpgDocLoad for JwpgDocLoad;
create public synonym JxtpBuff for JxtpBuff;

set long 32000
set serverout on
prompt Running JUnit test suite against DBPrism Toolkit HTTP wrappers
CALL dbms_java.set_output(32000);
prompt Running com.prism.toolkit.http.test.JxtpHttpServletRequestTest
call OJVMRunner('c','com.prism.toolkit.http.test.JxtpHttpServletRequestTest');
prompt Running com.prism.toolkit.http.test.JxtpHttpServletResponseTest
call OJVMRunner('c','com.prism.toolkit.http.test.JxtpHttpServletResponseTest');

commit;
exit

